*******************************************************************************
* DLog1
*
* (C)  Copyright Apple Computer, Inc. 1988
* All rights reserved.
*
* by Jim Mensch
* 7/11/88
*
* Demo of the Apple IIgs Dialog manager. This program shows how to create and 
* work with standard dialog boxes, both Modal and Modeless. It also has a demo
* of simple alerts. The dialogs used are from the examples in the toolbox ref
* manual volume 1. The Modal example implements a save current value feature.
*
* Files: 	System macros and equates
*	StandardLib.Aii
*
*
*
* Modification History:
*
* Version 1.0	Jim Mensch
*
*      7/11/88
*
*      Initial release
*
*******************************************************************************
**********************************************************************
*                                                                    *
*             Apple IIGS Source Code Sampler, Volume I               *
*                                                                    *
*             Copyright (c) Apple Computer, Inc. 1988                *
*                       All Rights Reserved                          *
*                                                                    *
*            Written by Apple II Developer Tech Support              *
*                                                                    *
*                                                                    *
*                                                                    *
*  ----------------------------------------------------------------  *
*                                                                    *
*     This program and its derivatives are licensed only for         *
*     use on Apple computers.                                        *
*                                                                    *
*     Works based on this program must contain and                   *
*     conspicuously display this notice.                             *
*                                                                    *
*     This software is provided for your evaluation and to           *
*     assist you in developing software for the Apple IIGS           *
*     computer.                                                      *
*                                                                    *
*     DISCLAIMER OF WARRANTY                                         *
*                                                                    *
*     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
*     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
*     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
*     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
*     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
*     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
*     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
*     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
*     REPAIR OR CORRECTION.                                          *
*                                                                    *
*     Apple does not warrant that the functions                      *
*     contained in the Software will meet your requirements          *
*     or that the operation of the Software will be                  *
*     uninterrupted or error free or that defects in the             *
*     Software will be corrected.                                    *
*                                                                    *
*     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
*     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
*     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
*     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
*     WHICH VARY FROM STATE TO STATE.                                *
*                                                                    *
*                                                                    *
**********************************************************************
	eject
	
	PRINT NOGEN,NOHDR
	STRING AsIS


	PRINT PUSH,OFF
	INCLUDE 'M16.Util'
	INCLUDE 'M16.ProDOS'
	INCLUDE 'M16.QUICKDRAW'
	Include 'E16.Quickdraw'
	INCLUDE 'M16.MEMORY'
	Include 'E16.Memory'
	INCLUDE 'M16.EVENT'
	INCLUDE 'M16.LOCATOR'
	INCLUDE 'M16.MISCTOOL'
	INCLUDE 'M16.TextTOOL'
	INCLUDE 'M16.Menu'
	INCLUDE 'M16.Control'
	Include 'E16.Window'
	INCLUDE 'M16.Window'
	INCLUDE 'M16.Dialog'
	Include 'E16.Dialog'
	INCLUDE 'M16.LineEdit'
	Include 'M16.List'
	INCLUDE 'M16.IntMath'
	INCLUDE 'M16.Scrap'
	INCLUDE 'M16.Desk'
	PRINT ON

DPHandle	equ 0	; handle to Tool Direct Page area
DPPointer	equ DPHandle+4	; Pointer to Tool Direct Page area
DeRef	equ DPPointer+4	; Temprary Handle dereference area
ScreenMode	equ Mode640	; used to set scan line SCB
ScreenWidth	equ 640	; used to set mouse	clamps 	  

CloseItem	equ 255	; menu item number for close item

	EJECT
*******************************************************************************
*
DLog1	PROC
*
* Description:	This is the main routine of the program. It simply calls
*	all the other major parts of the program.
*
*
* Inputs:	None
*
* Outputs:	None
*
* External Refs:
	Entry InitTools
	Entry InitApp
	Entry EventLoop
	Entry CloseTools
	Import QuitParms
*
* Entry Points:	None
*
*******************************************************************************


	jsr InitTools
	jsr InitApp

	_ShowCursor

	jsr EventLoop
	jsr CloseTools

	_Quit QuitParms

	EndP

	EJECT
*******************************************************************************
*
Globals	RECORD
*
* Description:	Global data for use in all routines of this demo. This area
*	also contains the data used by StandardLib.aii	
*
*
* Inputs:	None
*
* Outputs:	None
*
* External Refs:	None
*
* Entry Points:
	export QuitParms	; used by Main
*
*******************************************************************************
*
* Standard global data
*
*******************************************************************************

TitleString	str 'Apple IIgs Dialog Mgr Example Application'
AutString	str 'By Mensch Apple DTS ©1988 Apple Computer'
VersString	str 'Version: 1.0'

MenuHeight	ds.B 2	; Stored height of menu bar
MyID	ds.B 2	; Application ID
MyDP	ds.B 2	; My direct page storage

QuitFlag	ds.B 2
QuitParms	dc.L 0	; Pathname of next app
	dc.W $00	; flags

EventRecord
EventWhat	ds.B 2
EventMessage	ds.B 4
EventWhen	ds.B 4
EventWhere	ds.B 4
EventModifiers	ds.B 2
TaskData	ds.B 4
TaskMask	dC.L $0000FFFF

	EJECT
*******************************************************************************
*
* Application specific global data
*
*******************************************************************************

; This is a list of pointers to the text that is used to create our menus. It
; is used by InitApp to find all of the menu templates and use them to create
; our menubar. This loop loads MenuPtrLen-4 into an index, gets the
; corresponding menu template pointer in this table, and uses that in a
; NewMenu call. It then decrements the index by 4, and repeats the procees
; until the index is negative.

MenuPtr	dc.l AppMenu
	dc.l FileMenu
	dc.l EditMenu
MenuPtrLen	equ *-MenuPtr


; Menu list: menu items should be numbered consecutivly starting from 250.
; As a convention, use 256 as about and 257 as Quit.

AppMenu	dc.B '$$@\N1',$0D
	dc.B '--About Simple Dialog...\N256V',$00
	dc.B '.'
FileMenu	dc.B '$$  File  \N2',$00
	dc.B '--Modal Dialog Sample...\N258',$00
	dc.B '--Modeless Dialog Sample...\N259',$00
	dc.B '--Close\N255DV',$00
	dc.B '--Quit\N257*Qq',$0D
	dc.B '.'
EditMenu	dc.B '$$  Edit  \N3',$00
	dc.B '--Undo\N250*ZzVD',$00
	dc.B '--Cut\N251*XxD',$00
	dc.B '--Copy\N252*CcD',$00
	dc.B '--Paste\N253*VvD',$00
	dc.B '--Clear\N254D',$00
	dc.B '.'

; ModalTemplate is the template described in the Toolbox reference to be used
; with the getNewModalDialog call

ModalTemplate
	dc.W 30,30,120,330	; for 320 use 30,30,130,290
	dc.W $FFFF	; visible
	dc.L 0
	dc.L MTOKButton	; the ok button for	this dialog
	dc.L MTCancelButton	; cancel button
	dc.L MTTitle1	; title string of the dialog
	dc.L MTTitle2	; Title string of the Edit item
	dc.L MTRadio1	; Standard paper item
	dc.L MTRadio2	; legal pad item
	dc.L MTCheck	; stop printing item
	dc.L MTEdit	; edit box for page	title
	dc.L 0	; end of the item list

OKBTitle	str 'Ok'
CancelBTitle	str 'Cancel'
MTTitle1Str	str 'Print the document'
MTTitle2Str	str 'Title:'
MTCheckStr	str 'Stop printing after each page'
MTRadio1Str	str '8 1/2" x 11" paper'
MTRadio2Str	str '8 1/2" x 14" paper'
MTDefaultStr	ds.B 65
MTOKButton
	dc.W 1	; Item ID
	dc.W 30,240,45,295	; Item rectangle
	dc.W ButtonItem	; Item type
	dc.L OKBTitle	; Item Descriptor (	title )
	dc.W 0	; Initial value
	dc.W 0	; item flag ( 0 for	default )
	dc.L 0	; no color table

MTCancelButton
	dc.W 2
	dc.W 10,240,25,295
	dc.W ButtonItem
	dc.L CancelBTitle
	dc.W 0
	dc.W 0	; item flag
	dc.L 0	; no color table

MTTitle1
	dc.W 3
	dc.W 10,10,20,239
	dc.W StatText+ItemDisable
	dc.L MTTitle1Str
	dc.W 0
	dc.W 0	; item flag
	dc.L 0	; no color table

MTTitle2
	dc.W 4
	dc.W 67,10,77,60
	dc.W StatText+ItemDisable
	dc.L MTTitle2Str
	dc.W 0
	dc.W 0	; item flag
	dc.L 0	; no color table

MTRadio1
	dc.W 5
	dc.W 25,10,34,239
	dc.W RadioItem
	dc.L MTRadio1Str
MTRad1Def	dc.W 1	; default to on
	dc.W 1	; family 1
	dc.L 0

MTRadio2
	dc.W 6
	dc.W 35,10,49,239
	dc.W RadioItem
	dc.L MTRadio2Str
MTRad2Def	dc.W 0	; default to off	            
	dc.W 1	; family 1
	dc.L 0

MTCheck
	dc.W 7
	dc.W 50,10,64,280
	dc.W CheckItem
	dc.L MTCheckStr
MTCheckDef	dc.W 0
	dc.W 0
	dc.L 0

MTEdit
	dc.W 8
	dc.W 65,65,80,280
	dc.W editLine
	dc.L MTDefaultStr
	dc.W 60	; max length
	dc.W 0
	dc.L 0

BColorTab		; color table for use with color buttons
	dc.W $0050	; bttnOutline blue/red
	dc.W $00F0	; bttnNorBack white	background
	dc.W $00A0	; bttnSelBack yellow/green
	dc.W $00F0	; bttnNorText Black	text on White
	dc.W $00A0	; bttnSelText Black	on yellow/green
;
;   Modeless Dialog	Data 
;
ModelessPtr	ds.B 4
MLRect	dc.W 30,30,110,330	; for 320 use 30,30,130,290
MLTitle	str 'Change'
DLogHit	ds.B 4
DLogItemHit	ds.B 4

	EndR

	Include 'StandardLib.Aii'
	
	EJECT
*******************************************************************************
*
InitApp	PROC
*
* Description:	This routine is called once after the tools are started.
*	This is where you would create objects your program will
*	need at the very start, or initialize variables that require
*	an Initial default value.
*
*
* Inputs:	None
*
* Outputs:	None
*
* External Refs:
	With Globals
*
* Entry Points:	None
*
*******************************************************************************

	Stz QuitFlag	; initialize the quit flag
	stz ModelessPtr	; zero the modeless	pointer to signify
	stz ModelessPtr+2	; it is not already up

	rts
	EndP


	EJECT
*******************************************************************************
*
EventLoop	PROC
*
* Description:	Main event loop. Handles all user events and calls various
*	routines based on them. This routine ends when the user 
*	selects Quit.
*	
*
*
* Inputs:	None
*
* Outputs:	None
*
* External Refs:
	With Globals
	Import ModeLessEvent
	Import MenuSelect
	Import DoClose
	Import Ignore
*
* Entry Points:	None
*
*******************************************************************************
	
	PushWord #0	; room for result
	PushWord #$FFFF	; handle all tasks
	PushLong #EventRecord ; pointer to event record storage
	_TaskMaster
	
; Now that an event has occured we have to see if it is a dialog event. I do
; this by setting up a table of all possible events and specifying for each
; event type, whether it should be tested as a dialog event. If it turns out to
; be a dialog event, I change the EventType variable to 15 (app event 4)
; and proceed with my normal event dispatch. This will cause the event to be
; passed to my dialog event handler.

	pla	; get the event type
	sta EventType	; save it for after	dialog select
	tax	; use as index into	dlog event flags
	lda DlogEFlags,x	; to see if its an event dialogs
	and #$00FF	; might want
	bne EL0010	; nope branch around this!

	PushWord #0
	PushLong #EventRecord
	_IsDialogEvent
	pla
	beq EL0010	; false do nothing
	lda #15	; if true dispatch application event
	sta EventType	; #15 to signal a dialog event
EL0010
	lda EventType
	asl a	; multiply by 2
	tax
	jsr (TaskTable,x)

	lda QuitFlag
	beq EventLoop

	rts
EventType	ds.B 2
TaskTable	dc.W ModelessEvent	; 0 Null
	dc.W Ignore	; 1 MouseDown
	dc.W Ignore	; 2 Mouse Up
	dc.W Ignore	; 3 KeyDown
	dc.W Ignore	; 4 Undefined
	dc.W Ignore	; 5 AutoKey
	dc.W Ignore	; 6 Update
	dc.W Ignore	; 7 undefined
	dc.W Ignore	; 8 activate
	dc.W Ignore	; 9 Switch
	dc.W Ignore	; 10 desk acc
	dc.W Ignore	; 11 device driver
	dc.W Ignore	; 12 ap
	dc.W Ignore	; 13 ap
	dc.W Ignore	; 14 ap
	dc.W ModelessEvent	; 15 ap
	dc.W Ignore	; TASK 0 indesk
	dc.W MenuSelect	; TASK 1 in menuBar
	dc.W Ignore	; TASK 2 in system window
	dc.W Ignore	; TASK 3 in content
	dc.W Ignore	; TASK 4 in Drag
	dc.W Ignore	; TASK 5 in grow
	dc.W DoClose	; TASK 6 in goaway
	dc.W Ignore	; TASK 7 in zoom
	dc.W Ignore	; TASK 8 in info bar
	dc.W MenuSelect	; TASK 9 in special	menu
	dc.W Ignore	; TASK 10 in NDA
	dc.W Ignore	; TASK 11 in frame
	dc.W Ignore	; TASK 12 in drop	        
DLogEFlags
	dc.B 0	; null event
	dc.B 0	; 1 MouseDown
	dc.B 0	; 2 Mouse Up
	dc.B 0	; 3 KeyDown
	dc.B 1	; 4 Undefined
	dc.B 0	; 5 AutoKey
	dc.B 0	; 6 Update
	dc.B 1	; 7 undefined
	dc.B 0	; 8 activate
	dc.B 1	; 9 Switch
	dc.B 1	; 10 desk acc
	dc.B 1	; 11 device driver
	dc.B 1	; 12 ap
	dc.B 1	; 13 ap
	dc.B 1	; 14 ap
	dc.B 0	; 15 ap
	dc.B 1	; TASK 0 indesk
	dc.B 1	; TASK 1 in menuBar
	dc.B 1	; TASK 2 in system window
	dc.B 0	; TASK 3 in content
	dc.B 1	; TASK 4 in Drag
	dc.B 1	; TASK 5 in grow
	dc.B 1	; TASK 6 in goaway
	dc.B 1	; TASK 7 in zoom
	dc.B 1	; TASK 8 in info bar
	dc.B 1	; TASK 9 in special	menu
	dc.B 1	; TASK 10 in NDA
	dc.B 1	; TASK 11 in frame
	dc.B 1	; TASK 12 in drop	        
	EndP


	EJECT
*******************************************************************************
*
MenuSelect	PROC
*
* Description:	This routine is called when TaskMaster returns a menu
*	event. It takes the menu item that was hit and calculates
*	an offset into the menu dispatch table. It then calls that
*	routine and unhilites the menu when it is done.
*
* Inputs:	TaskData holds menu item selected.
*
* Outputs:	NONE
*
* External Refs:
	import ignore
	import doAbout
	import doQuit
	import Ignore
	Import DoModal
	import ShowModeless
	Import DoClose
*
* Entry Points:	NONE
*
*******************************************************************************
	With Globals

	lda TaskData	; Get the ID of the menu item selected.
	sec	; Turn it into an index by subtracting
	sbc #250	; the starting ID number (25) and mul-
	asl a	; tiplying by 2 (each table entry con-
	tax	; sists of 2 bytes).
	jsr (menuTable,x)	; Call the routine behind it.

	PushWord #0	; Routine done - unhilite the menubar.
	PushWord taskData+2
	_HiLiteMenu

	rts

MenuTable	dc.W Ignore	; Undo Item (250)
	dc.W Ignore	; cut
	dc.W Ignore	; copy
	dc.W Ignore	; paste
	dc.W Ignore	; clear
	dc.W DoClose	; close 
	dc.W DoAbout	; about shell...
	dc.W DoQuit	; quit selected
	dc.W DoModal	; example Modal Dialog
	dc.W ShowModeless	; example Modeless Dialog

	ENDP

	EJECT
*******************************************************************************
*
Ignore	PROC
*
* Description:	Called when I want to ignore an event.
*
*
* Inputs:	NONE
*
* Outputs:	NONE
*
* External Refs:	NONE
*
* Entry Points:	NONE
*
*******************************************************************************

	rts
	ENDP


	EJECT
*******************************************************************************
*
DoQuit	PROC
*
* Description:	Sets the quitflag to $FFFF so that the event loop will
*	know that the user wants to stop this app.
*
*
* Inputs:	None
*
* Outputs:	None
*
* External Refs:	None
*
* Entry Points:	None
*
*******************************************************************************
	With Globals

	lda #$FFFF
	sta QuitFlag
	rts
	EndP

	EJECT
*******************************************************************************
*
DoClose	PROC
*
* Description:	When the user selects the Close box of our modeless dialog or
*	the close menu Item. This routine will be called to put the dialog
*	away and clear the pointer to 0 to indicate that no Modeless dialog
*	is currently active.
*
*
* Inputs:	None
*
* Outputs:	None
*
* External Refs:	None
*
* Entry Points:	None
*
*******************************************************************************
	With Globals

	PushLong ModelessPtr
	_CloseDialog	; dump the dialog box

	stz ModelessPtr	; zero the pointer to show that it 
	stz ModelessPtr+2	; is put away!

	PushWord #CloseItem	; windows gone diable close
	_DisableMItem	; 

	rts
	EndP

	EJECT
*******************************************************************************
*
ModelessEvent	PROC
*
* Description:	This routine will be called every time an event occurs that
*	a modeless dialog should hear about. First, this routine 
*	checks to see if any modeless dialog exists, if not it  
*	exits. If one does exist, this routine handles the event.
*
*
* Inputs:	None  (All info passed in the event record)	
*
* Outputs:	None
*
* External Refs:	None
*
* Entry Points:	None
*
*******************************************************************************
	With Globals

	lda ModelessPtr
	ora ModelessPtr+2	; test to see if dialog exists first
	bne MLE0010	; if non-zero then its up
	rts

MLE0010
	PushWord #0	; room for result
	PushLong #EventRecord ; pointer to the event that occured
	PushLong #DlogHit	; Storage for the dialogs grafport 
	PushLong #DlogItemHit ; pointer to the item that was hit
	_DialogSelect
	pla	; anything hit?
	bne MLE0100	; if so handle the hit
	rts	; else DialogSelect	did what was needed

MLE0100
	_Sysbeep	; beep on any selected item

	rts	; go back to the event loop
	EndP

	EJECT
*******************************************************************************
*
ShowModeless	PROC
*
* Description:	Called when the user wants to display the modeless dialog.
*	If the dialog is already displayed, this routine does nothing.
*
*
* Inputs:	None
*
* Outputs:	None
*
* External Refs:	None
*
* Entry Points:	None
*
*******************************************************************************
	With Globals

	lda ModelessPtr	; first test to see	if box
	ora Modelessptr+2	; is already up
	beq DML0010	; if 0 then its not	up
	rts	; if nonzero then it is
DML0010
	PushLong #0	; room for result
	PushLong #MLRect	; bounds rect pointer
	PushLong #MLTitle	; box title
	PushLong #-1	; behind pointer (-1, in front of all)
	pushWord #fTitle+fClose+fMove+fVis ; dFlag
	PushLong #0	; ref con of dialog
	PushLong #0	; zoomed rectangle,	0= no zooming
	_NewModelessDialog
	PullLong ModelessPtr ; store the result	in dialog ptr

	PushLong ModelessPtr ; now add the dialog items
	PushLong #MLINext	; first add the next button
	_GetNewDItem

	PushLong ModelessPtr
	PushLong #MLIAll
	_GetNewDItem

	PushLong ModelessPtr
	PushLong #MLIStat1
	_GetNewDItem

	PushLong ModelessPtr
	PushLong #MLIStat2
	_GetNewDItem

	PushLong ModelessPtr
	PushLong #MLIEdit1
	_GetNewDItem

	PushLong ModelessPtr
	PushLong #MLIEdit2
	_GetNewDItem

	PushWord #CloseItem	; we now have the dialog up so 
	_EnableMItem	; enable the close menu item

	rts
MLINextStr	str 'Change Next'
MLIAllStr	str 'Change All'
MLIStat1Str	str 'Find Text:'
MLIStat2Str	str 'Change to:'
MLIDefault	str ''
MLIEData1	dc.B 31	; data max will be 30 characters
MLIEData2	dc.B 31	; data max will be 30 characters
MLINext		; Item Templates
	dc.W 1	; Item 1
	dc.W 55,10,70,120	; bounding rectangle
	dc.W ButtonItem	; Item Type
	dc.L MLINextStr	; descriptor ( title )
	dc.W 0	; initial value
	dc.W 0	; item flag
	dc.L BColorTab	; Custom color table

MLIAll
	dc.W 2
	dc.W 55,180,70,290
	dc.W ButtonItem
	dc.L MLIAllStr
	dc.W 0
	dc.W 3	; Single outline square dropshadow
	dc.L BColorTab	; Custom color table

MLIStat1
	dc.W 3
	dc.W 12,10,22,90
	dc.W StatText+ItemDisable
	dc.L MLIStat1Str
	dc.W 0
	dc.W 0	; item flag
	dc.L 0	; default color table

MLIStat2
	dc.W 4
	dc.W 32,10,42,90
	dc.W StatText+ItemDisable
	dc.L MLIStat2Str
	dc.W 0
	dc.W 0	; item flag
	dc.L 0	; default color table

MLIEdit1
	dc.W 5
	dc.W 10,100,25,290
	dc.W EditLine+ItemDisable
	dc.L 0	; 0 for no default text
	dc.W 30	; maximum length
	dc.W 0	; item flag
	dc.L 0	; default color table

MLIEdit2
	dc.W 6
	dc.W 30,100,45,290
	dc.W EditLine+ItemDisable
	dc.L MLIDefault	; default string
	dc.W 30
	dc.W 0	; item flag
	dc.L 0	; default color table


	EndP

	EJECT
*******************************************************************************
*
DoModal	PROC
*
* Description:	Displays the modal Dialog and handles all events that
*	occur until the OK or Cancel buttons are pressed. If the
*	OK button is pressed, this routine also copies the current
*	data from some of the items into the item default area so
*	the next time the dialog box is brought up, it reflects the
*	users last selections.
*
*
* Inputs:	None
*
* Outputs:	None
*		
* External Refs:	None
*
* Entry Points:	None
*
*******************************************************************************
	With Globals

	PushLong #0	; room for result
	PushLong #ModalTemplate ; pointer to dialog template
	_GetNewModalDialog
	PullLong DialogHandle ; pull Dialog pointer for later

ModalLoop
	PushWord #0	; Space for result
	PushLong #0	; Filter procedure ( 0 for none )
	_ModalDialog
	pla
	sta ItemHit

	cmp #3	; test if its an exit condition
	blt ModalDone	; is so, then we are done   
	cmp #7	; see if the check box was hit
	bne ML0010	; if not test more
	brl ModalCheckHit	; the check box was	hit
ML0010
	blt ModalRadioHit	; one of the radio buttons was hit
	brl ModalLoop	; This should bever	happen!

ModalDone
	cmp #1	; was it the OK button?
	bne MD0020	; no, then Don't save or act on changes
	jsr SetIt	; else, reset defaults
MD0020
	PushLong DialogHandle ; get rid of the dialog box
	_CloseDialog
	rts

ModalRadioHit
; This routine sets the selected radio button. NOTE: since the radio buttons
; have the same family number, this routine also resets the other buttons.

	Pushword #$FFFF	; now set selected button
	PushLong DialogHandle
	PushWord ItemHit
	_SetDItemValue
	brl ModalLoop

ModalCheckHit		; Handle a hit in the check box
	PushWord #0
	PushLong DialogHandle
	PushWord ItemHit
	_GetDItemValue	; first get the existing value
	pla	; retrieve the value
	and #$0001	; strip off all high bits
	eor #$0001	; and toggle bit 0
	pha	; now use it as the	new value
	PushLong DialogHandle
	PushWord ItemHit
	_SetDItemValue
	brl ModalLoop

SetIt		; ok was hit so retrieve
	PushWord #0	; values and save them as default 
	PushLong DialogHandle ; in template for	next time
	PushWord #5
	_GetDItemValue
	PullWord MTRad1Def

	PushWord #0
	PushLong DialogHandle
	PushWord #6
	_GetDItemValue
	PullWord MTRad2Def

	PushWord #0
	PushLong DialogHandle
	PushWord #7
	_GetDItemValue
	PullWord MTCheckDef

	PushLong DialogHandle
	PushWord #8	; now retrieve the text and use it
	PushLong #MTDefaultStr
	_GetIText
	rts

ItemHit	ds.B 2
DialogHandle	ds.B 4
	EndP

	END

